package ooday02;

import java.util.Scanner;

public class animaldemo {
    public static void main(String[] args) {
//        dog gou=new dog("red",3,"xiaogou");
//        chick ji=new chick("black",2,"xiaoji");
//        fish yu=new fish("white",1,"xiaoyu");


//        dog[] dogs=new dog[4];
//        dogs[0]=new dog("blue",3,"langou");
//        dogs[1]=new dog("red",3,"honggou");
//        dogs[2]=new dog("white",3,"baigou");
//        dogs[3]=new dog("black",3,"heigou");
////        dog[] dogs=new dog[2];
//        Scanner sc=new Scanner(System.in);
//        for(int i=0;i<dogs.length;i++){
//            System.out.println("请修改第"+(i+1)+"只狗狗的年龄");
//            int age= sc.nextInt();
//
//            dogs[i].age=age;
//            System.out.println("请修改第"+(i+1)+"只狗狗颜色");
//            String color=sc.next();
//            dogs[i].color=color;
//            System.out.println("请修改第"+(i+1)+"只狗狗名字");
//            String name=sc.next();
//            dogs[i].name=name;
//        }
//        for(int i=0;i<dogs.length;i++){
//            System.out.println("第"+(i+1)+"只狗的名字"+dogs[i].name);
//            dogs[i].eat();
//       }
//        chick[] ch=new chick[4];
//        ch[0]=new chick("blue",3,"lanji");
//        ch[1]=new chick("red",3,"hongji");
//        ch[2]=new chick("white",3,"baiji");
//        ch[3]=new chick("black",3,"heiji");
//        for(int i=0;i<ch.length;i++){
//            System.out.println("第"+(i+1)+"只鸡的名字"+ch[i].name);
//            ch[i].eat();
//        }
//       fish[] fi=new fish[4];
//        fi[0]=new fish("blue",3,"lanyu");
//        fi[1]=new fish("red",3,"hongyu");
//        fi[2]=new fish("white",3,"baiyu");
//        fi[3]=new fish("black",3,"heiyu");
//        for(int i=0;i<ch.length;i++){
//            System.out.println("第"+(i+1)+"只鱼的名字"+fi[i].name);
//            fi[i].eat();

//                    }
        //多态。向上造型
//        animal/*引用类型*/ asdff=new dog("blue",3,"langou");//一个狗的对象是动物
//        //能点出来啥看引用类型
//        //构造方法会直接调用子类重写的方法
//         asdff.eat();
//         asdff.drink();
//         asdff.as();
         animal[] anim=new animal[3];

         anim[0]=new dog("blue",3,"langou");
         //向下zhau造型  强转
//
//        System.out.println(anim[0] instanceof dog);//判断anim[0]的类型是否为dog  用instanceof  结果为true 可以强转
//         dog d=(dog)anim[0];

         anim[1]=new fish("black",3,"heiji");

         anim[2]=new chick("white",3,"baiji");


        for(int i=0;i<anim.length;i++){
            System.out.println("第"+(i+1)+"只动物的名字"+anim[i].name);
            anim[i].eat();
            if(anim[i] instanceof dog){
                dog dog=(dog)anim[i];
                dog.lookhome();
            }
            if(anim[i] instanceof fish){
                fish fish=(fish)anim[i];
                fish.swimi();
            }
            if(anim[i] instanceof swimi){
                swimi s=(swimi)anim[i];
                s.swimi();

            }
            if(anim[i] instanceof chick){
                chick chick=(chick)anim[i];
                chick.layegg();
            }


       }


//        传参调用方法
//        master mas= new master();
//        dog a=new dog("blue",3,"langou");
//        fish fi =new fish("black",3,"heiji");
//        chick ch=new chick("white",3,"baiji");
//        mas.feed(a);
//        mas.feed(fi);
//        mas.feed(ch);
//   向下造型
//        animal an=new dog("blue",3,"langou");
//        System.out.println(an instanceof dog);
//        dog ani=(dog)an;
//        ani.lookhome();

    }

}
